package com.atguigu.exam;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 1)创建Student类，类中有属性name和age并封装属性
 2)重载Student的构造函数，一个是无参构造并，另一个是带两个参数的有参构造，要求在构造函数打印提示信息
 3)创建带main函数的NewInstanceTest类，利用Class类得到Student对象
 4)通过上述获取的Class对象分别调用Student有参函数和无参函数
 * @author xbd
 * @create 2021-06-01 18:05
 */

public class StudentTest {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<Student> studentClass = Student.class;
        Constructor<Student> con = studentClass.getConstructor();
        Student s = con.newInstance();
        System.out.println(s.toString());

        Constructor<Student> con1 = studentClass.getConstructor(String.class,int.class);
        Student s1 = con1.newInstance("张三",25);
        System.out.println(s1);
    }
}
